<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link rel="stylesheet" href="../../../static/font-awesome-4.7.0/css/font-awesome.min.css" >
    <link rel="stylesheet" href="../../../static/vui/css/vui.css">

    <script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../../../static/js/jquery.cookie.min.js"></script>
    <script type="text/javascript" src="../../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../../static/laydate/laydate.js"></script>
    <script type="text/javascript" src="../../../static/vui/js/vui.js"></script>
    <script type="text/javascript" src="../../../static/js/common.js"></script>
</head>
<body>

	<div id="formArea">
		<input type="hidden" name="companyId"/>
		<table class="table">
			<tr>
				<td class="required">账户名称</td>
				<td><input type="text" class="input" autocomplete="off" name="name"/></td>
			</tr>
			<!--<tr>
				<td class="required">所属机构</td>
				<td><div id="companyId"></div></td>
			</tr>-->
			<tr>
				<td>期初日期</td>
				<td><input type="text" n="date" class="input" id="initDate" readonly="readonly" autocomplete="off" name="initDate"/></td>
			</tr>
			<tr>
				<td>期初余额</td>
				<td><input type="text" n="money" value="0.00" class="input" autocomplete="off" name="initBalance"/></td>
			</tr>
		</table>

	</div>

<script>

var requestParams = app.getRequestParams();
$(function () {


	if(requestParams.id){
		app.request({
			url:'account/get',
			data:{id:requestParams.id},
			success:function(resp){
				if( resp.result==0 ){
					$('#formArea').append('<input type="hidden" value="'+requestParams.id+'" name="id"/>');
					$('#formArea input[name="organizationId_text"]').val(requestParams.organizationName);
					app.resetForm(resp.data);
                    laydate.render({
                        elem: '#initDate',value:new Date(parseInt(resp.data.initDate))
                    });
				}else{
					app.message(parent.layer,'获取选中信息失败【'+resp.data+'】',2);
				}
			}
		});
	}else{
        laydate.render({
            elem: '#initDate',value:new Date(app.getServerTime())
        });

        var company = {companyId:app.getCompanyId()};
        app.resetForm(company);
	}
});

app.getOkBtn().click(function(){
	if( !checkForm() ){
		return;
	}

	var url = 'account/insert';

	if(requestParams.id){
		url = 'account/update'
	}

	var data = app.serializeForm();
    data.initDate =new Date(data.initDate).getTime();

	app.request({
		url:url,
		data:data,
		success:app.actionSuccess_parent
	});

});

function checkForm(){
	var checkOptions = [
			{type:'input',name:'name',verify:[{type:'required'}]}
		];
	return app.checkForm(checkOptions);
}

</script>

</body>
</html>